<?php
header("Content-Type:text/html;charset=utf-8");
date_default_timezone_set('Asia/Shanghai');
session_start();

$con = mysqli_connect("localhost","root","root","ultrax");
// 检测连接
if (mysqli_connect_errno())
{
    die("连接失败: " . mysqli_connect_error());
}

$sql = "select * from pre_common_block_shareurl order by id desc";
if(!empty($_POST['id'])){
	$sql = "select * from pre_common_block_shareurl where id = {$_POST['id']} order by id desc";
}

if(!empty($_POST['title'])){
	$cons = '%'.$_POST['title'].'%';
	$sql = "select * from pre_common_block_shareurl where title like '{$cons}' order by id desc";
}
if(!empty($_POST['id']) && !empty($_POST['title'])){
	$cons = '%'.$_POST['title'].'%';
	$sql = "select * from pre_common_block_shareurl where id = {$_POST['id']} and title like '{$cons}' order by id desc";
}

$result = mysqli_query($con,$sql);
$sqls = "select COUNT(id) as counts from pre_common_block_shareurl";
$count = mysqli_query($con,$sqls);
$counts = mysqli_fetch_array($count,MYSQLI_ASSOC);
if(mysqli_num_rows($result) > 0){
    $res = mysqli_fetch_all($result,MYSQLI_ASSOC);
    echo json_encode(['code'=>1,'data'=>$res,'count'=>$counts['counts'],'msg'=>'请求数据存在']);
    exit;
}else{
	echo json_encode(['code'=>0,'data'=>'','msg'=>'数据为空']);
	exit;
}